<template>
  <el-dialog :class="'el-dialog-theme3'" v-model="isShow" fullscreen
    class="ptDialog roll-dialog pub_dialog" width="90%" title="检测内容" top="1vh" draggable :close-on-click-modal="false"
    align-center>
    <div>
      <p class="pinformation">搜索条件</p>
      <el-form ref="queryRef" label-width="80" :model="queryParams" :inline="true">
        <el-form-item label="检测类别：" prop="jclbId">
          <el-select filterable clearable v-model="queryParams.jclbId" @change="jclbChange">
            <el-option v-for="item in jclbTypeList" :key="item.jclbId" :value="item.jclbId"
              :label="item.jclbName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="点位名称：" prop="pointIds">
          <el-select filterable clearable multiple collapse-tags-tooltip collapse-tags :max-collapse-tags="1"
            v-model="queryParams.pointIds" style="width:300px">
            <el-option v-for="item in pointList" :key="item.pointId" :value="item.pointId"
              :label="item.pointName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检测项目：" prop="jcxmName">
          <el-input @keyup.enter="handleQuery" clearable maxlength="100" v-model="queryParams.jcxmName" />
        </el-form-item>
        <el-form-item label="检测方法：" prop="method">
          <el-input @keyup.enter="handleQuery" clearable maxlength="100" v-model="queryParams.method" />
        </el-form-item>
        <el-form-item label="是否分包：" prop="isPackage">
          <el-select clearable v-model="queryParams.isPackage">
            <el-option v-for="dict in isPackageList" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)" />
          </el-select>
        </el-form-item>
        <el-form-item style="padding-left: 10px">
          <el-button type="success" @click="handleQuery">搜索</el-button>
          <el-button class="resetBtn" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row>
        <p class="pinformation">检测内容列表</p>
        <p class="totalStyle">共 {{ total }} 条数据</p>
      </el-row>
      <el-table border :data="tableData" ref="dataTableRef" v-loading="loading">
        <el-table-column align="center" width="160" show-overflow-tooltip label="点位检测类别" prop="point.pointJclbName" />
        <el-table-column align="center" width="170" show-overflow-tooltip label="点位名称" prop="pointName" />
        <el-table-column align="center" width="160" show-overflow-tooltip label="检测项目">
          <template #default="scope">
            <span v-html="proxy.getSupAndSub(scope.row.jcxmName)"></span>
          </template>
        </el-table-column>
        <el-table-column align="center" show-overflow-tooltip label="检测方法" prop="methodName">
          <template #default="scope">
            <span v-html="scope.row.methodCode + ' ' + proxy.getSupAndSub(scope.row.methodName)
              "></span>
          </template>
        </el-table-column>
        <el-table-column label="是否分包" align="center" width="100" show-overflow-tooltip>
          <template #default="scope">
            {{
              scope.row.isPackage == 0 ? "否" : (scope.row.isPackage == 1 ? "分包采样" : "分包不采样")
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" width="150" show-overflow-tooltip label="分包公司" prop="packageName" />
        <el-table-column label="检测项目组别" align="center" width="110" prop="groupName" show-overflow-tooltip />
        <el-table-column label="是否求和" align="center" width="85">
          <template #default="scope">
            <span v-if="scope.row.groupId && scope.row.isSum == 0">否</span>
            <span v-if="scope.row.groupId && scope.row.isSum == 1">是</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="85" show-overflow-tooltip label="采样天数" prop="sampleDay" />
        <el-table-column align="center" width="85" show-overflow-tooltip label="每天频次" prop="sampleCount" />
        <el-table-column label="评价标准" align="center" width="160" show-overflow-tooltip prop="pjName" />
        <el-table-column label="上限" align="center" width="110" prop="maxValue" />
        <el-table-column label="下限" align="center" width="110" prop="minValue" />
        <el-table-column label="指定方法" align="center" width="85">
          <template #default="scope">
            <span v-if="scope.row.isMethod == 0">否</span>
            <span v-if="scope.row.isMethod == 1">是</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="160" show-overflow-tooltip label="项目检测类别" prop="jclbName" />
      </el-table>
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
  </el-dialog>
</template>

<script setup>
import { listJclb, listTaskJcxm, listPoint1 } from "@/api/contract/taskPoint";
const { proxy } = getCurrentInstance();
const queryParams = ref({ pageNum: 1, pageSize: 10, isPackage: -1 });
const tableData = ref([]);
const total = ref(0);
const projectId = ref("");
const loading = ref(false);
const jclbTypeList = ref([]);
const heightParams = ref([{ tableName: "data", bottomHeight: 21 }]);
const isShow = ref(false);
const pointList = ref([]);
const isPackageList = ref([
  { value: -1, label: "不限" },
  { value: 0, label: "否" },
  { value: 1, label: "分包采样" },
  { value: 2, label: "分包不采样" },
]);
function getForm(val) {
  queryParams.value.primaryId = val;
  listJclb(queryParams.value.primaryId).then((res) => {
    jclbTypeList.value = res.data;
    if (jclbTypeList.value.length == 1) {
      queryParams.value.jclbId = jclbTypeList.value[0].jclbId;
      jclbChange(queryParams.value.jclbId, true);
    }
  });
  getList();
}

function getList() {
  loading.value = true;
  listTaskJcxm(queryParams.value).then((res) => {
    tableData.value = res.rows;
    total.value = res.total;
    loading.value = false;
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  pointList.value = [];
  handleQuery();
}

function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "data", bottomHeight: 85 }];
    } else {
      heightParams.value = [{ tableName: "data", bottomHeight: 30 }];
    }
    getTableHeight();
  }
);

const pointTable = ref([]);

function jclbChange(val, isFirst) {
  debugger;
  queryParams.value.pointIds = null;
  // delete queryParams.value.pointId
  if (val) {
    listPoint1({ jclbId: val, primaryId: queryParams.value.primaryId }).then((res) => {
      pointList.value = res.data;
    });
  }
  if (!typeof isFirst != "boolean") {
    getList();
  }
  // else {
  // 	pointTable.value = []
  // }
}

// 对外暴露以下方法或变量
defineExpose({
  isShow,
  getForm,
});
</script>

<style></style>
